package app.biz.model;

import app.framework.exception.ValidateException;
import org.apache.commons.codec.Encoder;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.Md5Crypt;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.security.provider.MD5;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * ECG远程服务请求对象
 * */
public class   EcgRequest {
  private static final Logger logger = LoggerFactory.getLogger(EcgRequest.class);

//  public static EcgRequest instance = new EcgRequest();

  public static EcgRequest instance(){
    return new EcgRequest();
  }

  private long sid;

  /** xml 心电数据*/
  private String xmlData;

  /** 采样率 {500,1000} 目前是二值的一种*/
  private int fs;

  /** 设备号 {0,1,2} 目前是三值中的一种*/
  private int device_id;

  /** 导联数 {12} 目前只能是单值*/
  private int leads;

  /** 避免冗余垃圾数据 **/
  private String md5;

  public int getFs() {
    return fs;
  }

  public EcgRequest setFs(int fs) {
    this.fs = fs;
    return this;
  }

  public int getDevice_id() {
    return device_id;
  }

  public EcgRequest setDevice_id(int device_id) {
    this.device_id = device_id;
    return this;
  }

  public int getLeads() {
    return leads;
  }

  public EcgRequest setLeads(int leads) {
    this.leads = leads;
    return this;
  }

  public String getXmlData() {
    return xmlData;
  }

  public EcgRequest setXmlData(String xmlData) {
    this.xmlData = xmlData;
    // 设置md5
    this.md5 = DigestUtils.md5Hex(xmlData);
    return this;
  }

  public  void validate() throws ValidateException {
    Validate.notNull(this.sid);
    if(500!=this.fs && 1000!=this.fs){
      throw new ValidateException("采样率参数错误：目前只支持500和1000 | "+fs);
    }
    if(device_id<0 || device_id>2){
      throw new ValidateException("设备号错误：目前只支持0、1、2 | "+device_id);
    }
    if(12!=this.leads){
      throw new ValidateException("导联参数错误：目前支持12导联 | "+leads);
    }
  }

  public long getSid() {
    return sid;
  }

  public String getMd5() {
    return md5;
  }

  public void setSid(long sid) {
    this.sid = sid;
  }

}
